package com.cci.kangdao.dao;

import com.cci.kangdao.dao.model.DictionariesT;
import org.apache.ibatis.annotations.MapKey;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.mybatis.spring.annotation.MapperScan;

import java.util.List;
import java.util.Map;

/**
 * 字典类dao
 *
 */
@MapperScan
public interface DictionariesTDao {

	//根据DTableName获取对应字典项集合
	@Select("select DValue as serviceNo,Remark as serviceName from Dictionaries_T where DTableName = 'GMST' and Flag = 0")
	List<Map<String,Object>> getServiceLevelList();

	//获取出行类型字典项
	@Select("select DInt,DValue from Dictionaries_T where DTableName = 'GoOutType' and Flag = 0")
	List<Map<String,Object>> getGoOutTypeList();

	//获取问题等级字典项
	@Select("select DTableName,DInt,DValue,Flag from Dictionaries_T where DTableName = 'ProblemLevel' and Flag = 0")
	List<Map<String,Object>> getProblemLevelList();

	//获取用户行为字典项
	@Select("select DTableName,DInt,DValue,Flag from Dictionaries_T where DTableName = 'UserAction' and Flag = 0")
    List<Map<String, Object>> getUserActionList();

    //获取失效模式字典项
    @Select("select DTableName,DInt,DValue,Flag from Dictionaries_T where DTableName = 'InvalidModel' and Flag = 0")
    List<Map<String, Object>> getInvalidModelList();

    @Select("select ID,DTableName, DInt, DValue, Flag,Remark from Dictionaries_T where Flag = 0 order by DTableName, CAST(DInt AS INT) asc")
    List<Map<String, Object>> getAllDictionaries();


    @Select("<script>select stuff((select ','+ DValue from  Dictionaries_T where DTableName = 'SSAuth' and DInt in" +
            "<foreach collection='dint' item='item' open='(' separator=',' close=')'>#{item} </foreach> and Flag = 0 for xml path('')),1,1,'') as ssAuths  </script>")
    String getSSAuthDvaule(@Param("dint") List<String> dint);

    //根据字典表dtablename字段获取值
    @Select("select * from Dictionaries_T where DTableName = #{dTableName} and Flag = 0 order by DInt")
    List<Map<String, Object>> getDictionariesListByDTableName(@Param("dTableName") String dTableName);

    @Select("select top 1 DValue from Dictionaries_T where DTableName = #{dTableName} and Flag = 0")
    String getListByDTableName(@Param("dTableName") String dTableName);

    @Select("select top 1 DValue from Dictionaries_T where DTableName = #{dTableName} and DInt = #{dInt} and Flag = 0")
    String getListByDTableNameAndDInt(@Param("dTableName") String dTableName,@Param("dInt") String dInt);

    @MapKey("DValue")
    @Select("select DValue,DInt from Dictionaries_T where DTableName = #{dtableName} and Flag = 0")
	Map<String,Map<String,Object>> getDicListByDtableName(@Param("dtableName")String dtableName);

	//根据字典表dtablename字段获取值
	@Select("select * from Dictionaries_T where DTableName = #{dTableName} and Flag = 0 order by DInt")
	List<DictionariesT> getDictListByDTableName(@Param("dTableName")String dTableName);

    @Select("select top 1 DInt from Dictionaries_T where DTableName = #{dTableName} and  DValue = #{dValue} and Flag = 0")
    String getDIntByDTableNameAndDValue(@Param("dTableName") String dTableName,@Param("dValue") String dValue);

}
